package cn.xiaobai.listener;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import java.util.concurrent.Future;

import cn.xiaobai.consts.Trigger;
import cn.xiaobai.controller.MainApplication;
import cn.xiaobai.controller.TwoApplication;
import cn.xiaobai.domain.Event;
import cn.xiaobai.domain.Message;
import cn.xiaobai.service.AuthorServer;
import cn.xiaobai.utils.TaskPool;

/**
 * @Author yangdaji
 * @Date 2023/12/23
 * @PackageName cn.xiaobai.listener
 * @ClassName ClickedListener
 */
public class ClickedListener extends AbstractEventListener {

    private AuthorServer authorServer;


    public ClickedListener(Context context) {
        authorServer = new AuthorServer(context);
    }


    @Override
    protected void clicked(View v) {
        int id = v.getId();
        Event event = getClickBt(id);
        String username = String.valueOf(event.getUsername().getText());
        String password = String.valueOf(event.getPassword().getText());

        Trigger trigger = event.getTriggerBt(id);
        Future<?> future = TaskPool.submit(() -> {
            Message message = authorServer.doCall(username, password, trigger.getType());
            if (message.getSuccess()) {
                Intent intent = new Intent(v.getContext(), TwoApplication.class);
                intent.putExtra("login_msg", message.getMsg());
                v.getContext().startActivity(intent);
            }
        });

    }

}


















